from dataclasses import dataclass
from typing import List, Optional, Tuple

@dataclass
class OcrResult:
    """OCR识别结果类"""
    text: str
    confidence: float
    box: Optional[List] = None
    
    def get_center(self) -> Optional[Tuple[int, int]]:
        """获取文字中心位置"""
        if not self.box:
            return None
        x = int(sum(point[0] for point in self.box) / 4)
        y = int(sum(point[1] for point in self.box) / 4)
        return (x, y) 